package com.acwing.partition11;

import java.io.*;

/**
 * @author `RKC`
 * @date 2021/12/10 9:37
 */
public class AC1018最低通行费 {

    private static final int N = 110;
    private static int[][] g = new int[N][N], f = new int[N][N];
    private static int n;

    private static StreamTokenizer tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    private static PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = nextInt();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                g[i][j] = nextInt();
            }
        }
        writer.println(resolve());
        writer.flush();
    }

    private static int resolve() {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == 0 && j == 0) f[i][j] = g[i][j];
                else {
                    f[i][j] = 0x3f3f3f3f;
                    if (i > 0) f[i][j] = Math.min(f[i][j], f[i - 1][j] + g[i][j]);
                    if (j > 0) f[i][j] = Math.min(f[i][j], f[i][j - 1] + g[i][j]);
                }
            }
        }
        return f[n - 1][n - 1];
    }

    private static int nextInt() throws IOException {
        tokenizer.nextToken();
        return (int) tokenizer.nval;
    }
}
